#include<bits/stdc++.h>

using namespace std;

typedef long long ll;

const int N = 2e5+5;

struct node
{
	int l,r;
	ll val,lz;
}tr[N<<2];
ll a[N];
void build(int p,int l,int r){
	if(l == r) {
        tr[p]={l,r,a[l],0};
        return;
    }
    tr[p].l = l,tr[p].r = r;
	int mid = (l+r)>>1;
	build(p<<1,l,mid);
	build(p<<1|1,mid+1,r);
	tr[p].val = tr[p<<1].val + tr[p<<1|1].val;
}
void pushdown(int k){
	tr[k<<1].lz +=tr[k].lz;
	tr[k<<1|1].lz +=tr[k].lz;
	tr[k<<1].val +=(tr[k<<1].r - tr[k<<1].l+1)*tr[k].lz;
	tr[k<<1|1].val +=(tr[k<<1|1].r - tr[k<<1|1].l+1)*tr[k].lz;
	tr[k].lz = 0;
}
void updown(int p,int L,int R,ll x){
	if(tr[p].l >= L && tr[p].r <= R) {
		tr[p].lz+=x;
		tr[p].val+=(tr[p].r - tr[p].l + 1)*x;
		return ;
	}
	if(tr[p].lz) pushdown(p);
	int mid = tr[p].l + tr[p].r>>1;
	if(R<=mid) updown(p*2,L,R,x);
	else if(L>mid) updown(p*2+1,L,R,x);
	else updown(p<<1,L,mid,x),updown(p<<1|1,mid+1,R,x);
	tr[p].val = tr[p<<1].val + tr[p<<1|1].val;
}
ll query(int p,int l,int r){
	if(l<=tr[p].l && tr[p].r<=r)    return tr[p].val;
	if(tr[p].lz) pushdown(p);
	int mid = tr[p].l+tr[p].r>>1;
	if(r<=mid) return query(p*2,l,r);
	else if(l>mid) return query(p*2+1,l,r);
	else return query(p*2,l,mid) + query(p*2+1,mid+1,r);
}
int main(){
	int n,m;
	cin>>n>>m;
	build(1,1,n);
	while(m--){
		int l,r;
		cin>>l>>r;
		updown(1,l,r,1);
	}
	std::vector<ll> v;
	for (int i = 1; i <=n; ++i)
	{
		ll t = query(1,i,i);
		v.push_back(t);
	}
	sort(v.begin(),v.end());
	ll cur = n,ans = 0;
	for (int i = v.size()-1; i >=0; --i)
	{
		ans=ans+v[i]*cur;
		cur--;
	}
	cout<<ans<<endl;
	return 0;
}

